#include "SpinTorque.h"

#include "Constants.h"
#include "Polarization.h"

#include <cmath>

SpinTorque::SpinTorque(Clock clock,Pulse * current,Layer mag,Layer pol,NewParameters params)
{
  double polarization=0;
  if(params.getPolarizationType()=="Slonczewski")
    {
      polarization=Polarization(mag,pol).Slonczewski(mag);
    }  
  if(params.getPolarizationType()=="Xiao")
    {
      polarization=Polarization(mag,pol).Xiao(params);
    }
  Vector3 torque1,torque2;
  torque1=torque2=mag.getMag();
  double betatemp=(Constants::GAMMA*Constants::HBAR*current->getLevel(clock.getTimeStamp())*polarization)/(2*Constants::MU0*Constants::E*mag.getMs()*mag.getThickness()*mag.getSurface());
  newBeta2=betatemp/(1+pow(mag.getAlpha(),2));
  newBeta1=newBeta2*mag.getAlpha();
  torque1.crossProduct(pol.getMag());
  torque2.crossProduct(torque1);
  torque1.mult(newBeta1);
  torque2.mult(-newBeta2);
  torque1.add(torque2);
  x=torque1.getX();
  y=torque1.getY();
  z=torque1.getZ();
}

SpinTorque::~SpinTorque()
{

}
